package com.s7.widget.attr;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.DisplayMetrics;

import androidx.annotation.ColorInt;

import com.s7.widget.R;
import com.s7.widget.utils.PxUtil;

public class WheelPickerAttr {

    /**
     * 未选择Item的Text的颜色、大小、画笔
     */
    @ColorInt
    private int mUnSelectedColor;
    private int mUnSelectedSize;

    /**
     * 字体渐变，开启后越靠近边缘，字体越模糊
     */
    private boolean isGradual;

    /**
     * 选中的Item的Text颜色、大小、画笔
     */
    @ColorInt
    private int mSelectedColor;
    private int mSelectedSize;

    /**
     * 指示器（会在中心文字后边多绘制一个文字）
     * 指示器文字、颜色、大小、画笔
     */
    private String mIndicator;
    @ColorInt
    private int mIndicatorColor;
    private int mIndicatorSize;

    /**
     * Item中的间距
     */
    private int mSpacing;


    /**
     * 显示未选中的Item条数（所有条数 = mHalfCount * 2 + 1）
     */
    private int mHalfCount;

    /**
     * 当前的Item的位置(默认位置)
     */
    private int mCurrent;

    /**
     * 是否将中间的Item放大(选中的)
     */
    private boolean isZoom;

    /**
     * 是否显示幕布，中央Item会遮盖一个颜色
     */
    private boolean isCurtain;

    /**
     * 幕布颜色
     */
    @ColorInt
    private int mCurtainColor;

    /**
     * 是否显示幕布的边框
     */
    private boolean isCurtainBorder;

    /**
     * 幕布边框的颜色
     */
    @ColorInt
    private int mCurtainBorderColor;

    /**
     * 是否循环读取数据
     */
    private boolean isCyclic;

    public WheelPickerAttr(Context context, AttributeSet attrs, int defStyleAttr) {
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.WheelPicker, defStyleAttr, 0);

        mHalfCount = ta.getInteger(R.styleable.WheelPicker_wpHalfCount, 2);
        mCurrent = ta.getInteger(R.styleable.WheelPicker_wpCurrent, 0);

        mSelectedColor = ta.getColor(R.styleable.WheelPicker_wpSelectedColor, 0xFF33AAFF);
        mSelectedSize = getSize(context, ta.getDimensionPixelSize(PxUtil.spToPx(R.styleable.WheelPicker_wpSelectedSize, context), 22));

        mUnSelectedColor = ta.getColor(R.styleable.WheelPicker_wpUnSelectedColor, 0xFF333333);
        mUnSelectedSize = getSize(context, ta.getDimensionPixelSize(PxUtil.spToPx(R.styleable.WheelPicker_wpUnSelectedSize, context), 18));

        isGradual = ta.getBoolean(R.styleable.WheelPicker_wpGradual, true);
        isZoom = ta.getBoolean(R.styleable.WheelPicker_wpZoom, true);
        isCyclic = ta.getBoolean(R.styleable.WheelPicker_wpCyclic, false);
        mSpacing = getSize(context, ta.getDimensionPixelSize(PxUtil.spToPx(R.styleable.WheelPicker_wpSpacing, context), 10));

        isCurtain = ta.getBoolean(R.styleable.WheelPicker_wpCurtain, true);
        mCurtainColor = ta.getColor(R.styleable.WheelPicker_wpCurtainColor, 0xFFFFFFFF);
        isCurtainBorder = ta.getBoolean(R.styleable.WheelPicker_wpCurtainBorder, true);
        mCurtainBorderColor = ta.getColor(R.styleable.WheelPicker_wpCurtainBorderColor, 0xFF33AAFF);

        mIndicator = ta.getString(R.styleable.WheelPicker_wpIndicator);
        mIndicatorColor = ta.getColor(R.styleable.WheelPicker_wpIndicatorColor, 0xFF33AAFF);
        mIndicatorSize = getSize(context, ta.getDimensionPixelSize(PxUtil.spToPx(R.styleable.WheelPicker_wpIndicatorSize, context), 18));
        ta.recycle();
    }

    private int getSize(Context context, float size) {
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        float value = dm.scaledDensity;
        return (int) (size * value);
    }

    public int getUnSelectedColor() {
        return mUnSelectedColor;
    }

    public int getUnSelectedSize() {
        return mUnSelectedSize;
    }

    public boolean isGradual() {
        return isGradual;
    }

    public int getSelectedColor() {
        return mSelectedColor;
    }

    public int getSelectedSize() {
        return mSelectedSize;
    }

    public String getIndicator() {
        return mIndicator;
    }

    public int getIndicatorColor() {
        return mIndicatorColor;
    }

    public int getIndicatorSize() {
        return mIndicatorSize;
    }

    public int getSpacing() {
        return mSpacing;
    }

    public int getHalfCount() {
        return mHalfCount;
    }

    public int getCurrent() {
        return mCurrent;
    }

    public boolean isZoom() {
        return isZoom;
    }

    public boolean isCurtain() {
        return isCurtain;
    }

    public int getCurtainColor() {
        return mCurtainColor;
    }

    public boolean isCurtainBorder() {
        return isCurtainBorder;
    }

    public int getCurtainBorderColor() {
        return mCurtainBorderColor;
    }

    public boolean isCyclic() {
        return isCyclic;
    }
}
